package com.fruit.web.vo.genl;

import java.util.List;





import javax.faces.application.FacesMessage;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.SelectItem;


import com.fruit.service.IFruitCategoryService;
import com.fruit.utils.MessageFactory;
import com.fruit.utils.SpringFacesUtil;
import com.fruit.web.bo.impl.FruitCategory;
import com.fruit.web.constant.EjdConstants;
import com.fruit.web.constant.SpringBeanConstants;

@ManagedBean(name="existFruitCategory")
@SessionScoped
public class ExistFruitCategoryBean implements java.io.Serializable {

	private SelectItem[] categoryItems;

	public SelectItem[] getCategoryItems() {
		return categoryItems;
	}

	public void setCategoryItems(SelectItem[] categoryItems) {
		this.categoryItems = categoryItems;
	}
	public ExistFruitCategoryBean() {
		
		IFruitCategoryService<FruitCategory,Long> subCategoryService = (IFruitCategoryService<FruitCategory,Long>)SpringFacesUtil.getSpringBean(SpringBeanConstants.FRUIT_CATEGORY_SERVICE_BEAN_NAME);
		subCategoryService.setEntityClass(FruitCategory.class);
		subCategoryService.setPKClass(Long.class);
		List<FruitCategory> subCategorys = subCategoryService.getAll("serialNumber",true);
		SelectItem[] tempSubCategoryItems = new SelectItem[subCategorys.size()];
		//set select default 
		if (null != subCategorys && !(subCategorys.isEmpty())) {
			for (int i=0; i< tempSubCategoryItems.length; i++) {
				FruitCategory subCategory = (FruitCategory) subCategorys.get(i);
				String subCategoryNameN18 = MessageFactory.getMessage(EjdConstants.USER_BUNDLE_NAME,subCategory.getCategoryName(), FacesMessage.SEVERITY_ERROR).getDetail();
				tempSubCategoryItems[i] = new SelectItem(subCategory.getCategoryCode(),subCategoryNameN18,subCategory.getCategoryCode());
			}
		}
		this.setCategoryItems(tempSubCategoryItems);
	}
}
